var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/businessComponent/work-flow/WorkFlowBatchStartWin.tsx
var WorkFlowBatchStartWin_exports = {};
__export(WorkFlowBatchStartWin_exports, {
  openWorkFlowBatchStartWin: () => openWorkFlowBatchStartWin
});
module.exports = __toCommonJS(WorkFlowBatchStartWin_exports);
var import_icons = require("@ant-design/icons");
var import_antd = require("antd");
var import_react = require("react");
var import_baseComponent = require("../../baseComponent");
var import_functionalComponent = require("../../functionalComponent");
var import_util = require("../../util");
var import_util2 = require("./util");
var columnProps = {
  sortable: false,
  resizable: false,
  columnSort: false
};
var global = {
  workInFlow: null,
  close: import_util.emptyFn,
  modalIns: null
};
function BatchStartFlowSuccess({ data }) {
  const mCtx = (0, import_react.useContext)(import_functionalComponent.ModalContext);
  const columns = (0, import_react.useMemo)(() => {
    return [
      {
        ...columnProps,
        tooltip: true,
        header: "单据编号",
        dataIndex: "dataId",
        flex: 1
      },
      {
        ...columnProps,
        tooltip: true,
        header: "送审结果",
        dataIndex: "success",
        flex: 3,
        render: (record) => {
          if (record.value) {
            return /* @__PURE__ */ React.createElement(import_antd.Tooltip, { title: record.row.message }, /* @__PURE__ */ React.createElement(import_icons.CheckCircleOutlined, { style: { color: "#339933" } }), " ", record.row.message);
          } else {
            return /* @__PURE__ */ React.createElement(import_antd.Tooltip, { title: record.row.message }, /* @__PURE__ */ React.createElement(import_icons.CloseCircleOutlined, { style: { color: "#ff3300" } }), " ", record.row.message);
          }
        }
      }
    ];
  }, []);
  (0, import_react.useEffect)(() => {
    mCtx.ins.setApi({
      invokeCancelHandler: async () => {
        var _a;
        (_a = mCtx.ins) == null ? void 0 : _a.destroy();
      }
    });
  }, []);
  return /* @__PURE__ */ React.createElement(import_util.Layout, { style: { height: 400, padding: 5 } }, /* @__PURE__ */ React.createElement(import_util.Layout.Flex, null, /* @__PURE__ */ React.createElement(import_functionalComponent.Table, { bordered: true, headerHeight: 32, rowHeight: 30, columns, dataSource: data })));
}
async function startFlow() {
  var _a, _b, _c;
  const { workInFlow } = global;
  const resp = await (0, import_functionalComponent.usingProgress)(
    () => import_util.iup.request.body({
      url: "workflow/process/batchStartProcessInstance",
      data: {
        processDefinitionId: workInFlow.startFlowParam.pdid,
        formData: workInFlow.formData,
        comment: {
          content: workInFlow.startFlowParam.remark
        }
      }
    }),
    { title: `${import_util2.NGLang.createFlow}...` }
  );
  (_a = global.close) == null ? void 0 : _a.call(global);
  if (resp.code === 0) {
    const dataList = resp.data.dataIdList.map((i) => {
      return {
        dataId: i,
        message: import_util2.NGLang.startFlowSuccess,
        success: true
      };
    }).concat(
      resp.data.failStartProcessMessages.map((i) => {
        return {
          ...i,
          success: false
        };
      })
    );
    (_b = workInFlow.callback) == null ? void 0 : _b.call(workInFlow, resp.data);
    await (0, import_util2.wfModal)({
      title: import_util2.NGLang.batchStartFlowSuccess,
      width: 600,
      okText: false,
      cancelText: "关闭",
      content: /* @__PURE__ */ React.createElement(BatchStartFlowSuccess, { data: dataList })
    });
  } else {
    await (0, import_util2.wfAlert)(import_util2.NGLang.createFlowError, resp.errorMsg);
    (_c = workInFlow.cancelback) == null ? void 0 : _c.call(workInFlow);
  }
}
function WorkFlowBatchStartWin() {
  const { workInFlow } = global;
  const tableRef = (0, import_util.useApi)();
  const mCtx = (0, import_react.useContext)(import_functionalComponent.ModalContext);
  const compProps = (0, import_react.useMemo)(() => {
    const iconStyle = { fontSize: 16, cursor: "pointer" };
    return {
      labelStyle: { width: 65, lineHeight: "32px" },
      tableProps: {
        headerHeight: 32,
        rowHeight: 30,
        style: { border: "1px solid var(--border-color-split, #f0f0f0)" },
        columns: [
          {
            ...columnProps,
            flex: 1,
            header: import_util2.NGLang.pdId,
            dataIndex: "id"
          },
          {
            ...columnProps,
            flex: 2,
            header: import_util2.NGLang.pdName,
            dataIndex: "name"
          },
          {
            ...columnProps,
            flex: 2,
            header: import_util2.NGLang.description,
            dataIndex: "description"
          }
        ],
        dataSource: workInFlow.data || []
      }
    };
  }, []);
  const [form, setForm] = (0, import_react.useState)({ txtRemark: "" });
  const onRemarkHandler = (0, import_util.useRefCallback)((txtRemark) => {
    setForm((p) => ({ ...p, txtRemark }));
  });
  const onSearchHandler = (0, import_util.useRefCallback)((value) => {
    tableRef.current.getApi().filter(value, ["id", "name"]);
  });
  const validDataAndStartFlow = (0, import_util.useRefCallback)(async () => {
    const selectData = tableRef.current.getApi().getSelectedData()[0];
    if (!selectData) {
      await (0, import_util2.wfAlert)(import_util2.NGLang.alertTitle, import_util2.NGLang.selectOnePd);
      return;
    }
    workInFlow.startFlowParam.pdid = selectData.id;
    workInFlow.startFlowParam.remark = form.txtRemark;
    await startFlow();
  });
  (0, import_react.useEffect)(() => {
    global.modalIns = mCtx.ins;
    mCtx.ins.setApi({
      invokeOkHandler: validDataAndStartFlow,
      invokeCancelHandler: async () => {
        var _a, _b, _c;
        await ((_b = (_a = global.workInFlow).cancelback) == null ? void 0 : _b.call(_a));
        (_c = global.close) == null ? void 0 : _c.call(global);
      }
    });
    tableRef.current.getApi().setSelected(0);
  }, []);
  return /* @__PURE__ */ React.createElement(import_util.Layout, { style: { height: 400, padding: "5px 12px" } }, /* @__PURE__ */ React.createElement(import_util.Layout, { direction: "row" }, /* @__PURE__ */ React.createElement("label", { style: compProps.labelStyle }, import_util2.NGLang.taskRemark, ":"), /* @__PURE__ */ React.createElement(import_util.Layout.Flex, null, /* @__PURE__ */ React.createElement(import_baseComponent.TextArea, { value: form.txtRemark, onChange: onRemarkHandler, rows: 3 }))), /* @__PURE__ */ React.createElement(import_util.Layout, { direction: "row", style: { margin: "5px 0" } }, /* @__PURE__ */ React.createElement("label", { style: { width: 65, lineHeight: "32px" } }, import_util2.NGLang.procDefin, ":"), /* @__PURE__ */ React.createElement(import_util.Layout.Flex, null, /* @__PURE__ */ React.createElement(import_baseComponent.Search, { placeholder: import_util2.NGLang.seachEmptyText, allowClear: true, onSearch: onSearchHandler }))), /* @__PURE__ */ React.createElement(import_util.Layout.Flex, null, /* @__PURE__ */ React.createElement(import_functionalComponent.Table, { ref: tableRef, ...compProps.tableProps })));
}
async function openWorkFlowBatchStartWin(props) {
  global.workInFlow = props;
  global.workInFlow.startFlowParam = {};
  global.close = () => {
    var _a;
    global.close = import_util.emptyFn;
    (_a = global.modalIns) == null ? void 0 : _a.destroy();
    global.modalIns = null;
  };
  await (0, import_util2.wfModal)({
    title: import_util2.NGLang.batchStartFlowWinTitile,
    content: /* @__PURE__ */ React.createElement(WorkFlowBatchStartWin, null),
    width: 650
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  openWorkFlowBatchStartWin
});
